<?php
/**
 * 作者:konakona
 * 版本号:1.0.0
 * 完工时间: 2009-10-26
 */
require('konakona/konakona.php');
k::run();
k::setEncoding();
template::assign('config',k::$config);
$c = isset($_GET['c'])?$_GET['c']:'index';
$id = @intval($_GET['id']);
$pid = @intval($_GET['p']);
error_reporting(E_ALL ^ E_NOTICE);
k::import( 'helper.page');
switch($c){
    case 'tour':
        if(isset($m)){
			template::assign('tour_page',page::enrun($pid,'tour','tour',10));
			template::assign('tour_list',tour::tour_list($pid,$m));
		}
		template::assign('district',$m);
		template::display('tour-list.html');
    break;
    case 'details':
        if(isset($m) && $m == 'tour'){
            template::assign('id',$id);
			template::assign('reviews_list',true);
            template::assign('tour_details',tour::tour_details($id));
            template::display('tour-details.html');
        }else if(isset($m) && $m=='guide'){
			template::assign('district',district::getDistrict());
			@guide::guide_clicknum($id);
			template::assign('guide_details',guide::guide_details($id));
			template::display('guide-details.html');
		}
    break;
	case 'reviews':
		template::assign('reviews_list',reviews::reviews_list($pid,false,5));
                page::set_Each_page(5);
		template::assign('reviews_page',page::enrun($pid,'tour_reviews','reviews'));
		template::display('reviews.html');
	break;
    case 'buy':
        if(isset($m) && $m=='tour'){
            template::assign('id',$id);//tid
            template::display('booking-form-tour.html');
        }else if($m=='cruise'){
            if(!isset($_GET['steps'])) $_GET['steps'] = 1;

            template::assign('id',$id);//fid

            if($_GET['steps']=='1'){
                    $city_list =cruise::city_list($id);	//航线列表
                    template::assign('city_list',$city_list);
                    template::assign('ship_name',flight::getName($id));//油轮名

                    //ajax
                    if($_GET['do']=='price'){
                            $city = explode(",",$_GET['en']);
                            $way = $city[1];
                            $monthdate = explode("-",$_GET['ym']);
                            echo flight::getPrice($_GET['fid'],$monthdate[1],$way);
                            exit;
                    }
                    if(isset($_GET['en'])){
                            $city = explode(",",$_GET['en']);
                            $weekstr = cruise::WeekTonum($city[2]);
                            echo $calendar = cruise::calendar($_GET['ym'],$city_list,$id,$weekstr);
                            exit;
                    }
                    if(isset($_GET['ym'])){
						echo $calendar = cruise::calendar($_GET['ym'],$city_list,$id,$week);
                    }else{
						template::assign('calendar',cruise::calendar(date("Y").date("n"),$city_list,$id,$city_list[0]['Begin_date']));
                    }
                    // endajax
					template::display('booking-form-cruise-1.html');//用户填写资料。
			}

              if($_GET['steps']=='2'){
					order::checkSteps1($_POST);
					template::display('booking-form-cruise-2.html');//确认用户填写资料,付款。
				}elseif($_GET['steps']=='3'){
					if($_SESSION['shipname']!=''){
						order::create_cruise_order();
					}else{
						k::message("shuaxin");
					}
				}
		}
    break;
    case 'submit':
        if(isset($m) && $m=='tour'){
            order::submit($_POST);
        }else if($m == 'comments'){
			comments::comments_add($_POST);
		}
    break;
	case 'news':
		if(isset($m) && $m=='details'){
			$news_details = news::news_details($id);
			if($news_details!=NULL)
			news::news_clicknum($id);
			template::assign('news_details',$news_details);
			template::display('news-details.html');
		}else{
			template::assign('news_page',page::enrun($pid,'news','news'));
			template::assign('news_list',news::news_list($pid,10));
			template::display('news-list.html');
		}
	break;
	case 'contact':
		if($_SERVER['REQUEST_METHOD']=='POST'){
			contact::run($_POST);
		}
		template::assign('RefusalAD',k::formhash());
		template::assign('title','Contact Us');
		template::display('contact-us.html');
	break;
    case 'pay':
	//cruise订单支付
	if($_GET['t']=='c'){
        if(isset($_GET['key'])){
            echo $_GET['key'];
			//验证KEY是否合法
			//从数据库提取价格和CID以及OID
			template::display('booking-form-cruise-3.html');
			
			$beforMd5 = getHmacValue(array('sw_sid','sw_p1','sw_p2','sw_p3','time','uniqid'));
	}
	//tour订单支付
	if($_GET['t']=='t'){
	
	}
        }
    break;
    case 'guide':
	if(isset($m)){
			template::assign('guide_list',guide::guide_list($pid,$m));
		}
		template::assign('guide_page',page::enrun($pid,'guide','guide'));
		template::assign('district',$m);
		template::display('guide-list.html');
    break;
	case 'cruise':
		if(isset($m) && $m=='schedule'){
			if(isset($_POST['month'])){
				template::assign('moon',cruise::NumTomonth($_POST['month']));
				template::assign('month',$_POST['month']);
				$data = cruise::cruise_month(date('Y',time()),$_POST['month']);
				template::assign('html',cruise::cruise_html($_POST['month'],$data));
			}else{
				template::assign('moon',date("F",time()));
				template::assign('month',date('n',time()));
				$data = cruise::cruise_month(date('Y',time()),date('n',time()));
				template::assign('html',cruise::cruise_html(date("n",time()),$data));
			}
			template::assign('city_list',cruise::city_list());
			template::display('cruise-schedule.html');
		}else if(isset($m) && $m='search'){
			cruise::check_search($_POST);
			$date = @explode("-",$_POST['date']);
			$fidandupdown = cruise::cruise_getFID($_POST['date'],k::escapeSQL($_POST['city']));
			if(empty($fidandupdown[0]['city_id'])) k::message('Not found');
			foreach($fidandupdown as $key=>$value){
				$result[] = cruise::search($value['fid'],$date[1],$date[0],$fidandupdown[0]['updown']);
			}
			template::assign('search',$result);
			template::assign('year',$date[0]);
			template::assign('month',$date[1]);
			template::assign('day',$date[2]);
			template::register_function('cutstr','k::cutstr');
			template::display('cruise-search.html');
		}
	break;
	case 'ship':
		if(isset($m) && $m=='show'){
			template::assign('menu','Cruise schedule');
			template::assign('FZAD',k::$config['FORMHASH']);
			template::assign('city_list',cruise::city_list());
			template::assign('ship_info',flight::flight_details($id));
			page::set_Each_page(5);//comments未指定fid
            template::assign('comments_page',page::enrun($pid,'comments',"ship-show-".$id,$id));
			template::assign('comments',comments::comments_list($pid,$id,5));
			template::display('ship-show.html');
		}
	break;
    case 'contact':
        template::display('contact.html');
    break;
    case 'index':
		$data = mysql::connect()->fetch_all("select * from flight ORDER BY fid DESC Limit 0,5");
        template::assign('cruise_list',$data);
		template::assign('news_list',news::news_list($pid,5));
		template::assign('tour_list',tour::tour_list($pid,'beijing',5));
        template::display('index.html');
    break;
}